import { FormRule, PrimaryTableCol, Tag } from 'tdesign-vue-next';

import { t } from '@/locales';

/**
 * 搜索表单项
 */
export const getSearchParams = (): _SearchParamsProps[] => [
  {
    label: t('pages.userRole.name'),
    key: 'name',
    hide: false,
  },
  {
    label: t('pages.userRole.code'),
    key: 'code',
    hide: false,
  },
  {
    label: t('pages.userRole.status'),
    key: 'status',
    hide: false,
    valueType: 'select',
    defaultValue: 0,
    options: [
      {
        label: t('pages.userRole.Text.enable'),
        value: 0,
      },
      {
        label: t('pages.userRole.Text.disable'),
        value: 1,
      },
    ],
  },
];

/**
 * 表格列
 */
export const getColumns = (): PrimaryTableCol[] => [
  {
    colKey: 'row-select',
    type: 'multiple',
    width: 50,
  },
  {
    title: t('pages.userRole.name'),
    ellipsis: true,
    align: 'center',
    colKey: 'name',
  },
  {
    title: t('pages.userRole.code'),
    ellipsis: true,
    align: 'center',
    colKey: 'code',
  },
  {
    title: t('pages.userRole.status'),
    align: 'center',
    colKey: 'status',
    cell: (h, { row }) =>
      h(
        Tag,
        {
          theme: row.status === 0 ? 'success' : 'danger',
          variant: 'light',
        },
        () => (row?.status === 0 ? t('pages.userRole.Text.enable') : t('pages.userRole.Text.disable')),
      ),
  },
  {
    title: t('pages.userRole.remark'),
    ellipsis: true,
    align: 'center',
    colKey: 'remark',
  },
];

/**
 * 表单校验规则
 */
export const getRules = (): Record<string, FormRule[]> => ({
  name: [{ required: true, message: t('pages.userRole.required.name'), type: 'error', trigger: 'blur' }],
  code: [{ required: true, message: t('pages.userRole.required.code'), type: 'error', trigger: 'blur' }],
});
